package main

import (
	"../src/actor"
	"fmt"
	"sync"
)

type SomeActor struct {
	i int
	actor.SimpleActor
}

func (this *SomeActor) Receive(msg interface{}, sender actor.Actor) {
	switch value := msg.(type) {
	case string:
		fmt.Println(sender.Name(), "-->", value)
//		sender.Stop()
	case *actor.Terminal:
		fmt.Printf("%s stopped \n", sender.Name())
	}

}

func (this *SomeActor) OnStart() {
	fmt.Println(this.Name() + " OnStart!!")

	b := Some2Actor{2, this.ActorOf("b")}
	actor.Register(&b)
	b.Tell("are you ok?", this.Self())
}


type Some2Actor struct {
	i int
	actor.SimpleActor
}

func (this *Some2Actor) Receive(msg interface{}, sender actor.Actor) {
	switch value := msg.(type) {
	case string:
		fmt.Println(sender.Name(), "-->", value)
		sender.Tell("yes, thank you.  " + sender.Name(), this.Self())
	}

}

func (this *Some2Actor) OnStart() {
	fmt.Println(this.Name() + " OnStart!!")
}

//func (this *Some2Actor) OnStop() {
//	fmt.Println("be killed")
//}


func main() {
	system := actor.System("system")
	system.Start(":7777")

	a := SomeActor{1, system.ActorOf("a")}

	actor.Register(&a)

	wait := sync.WaitGroup{}
	wait.Add(1)
	wait.Wait()

}
